package com.lcq.study.normal;

import java.util.Optional;

/**
 * @ClassName OptionalTest
 * @Description
 * @Author lichuanqi
 * @Date 2022/3/21 10:13
 * @Version 1.0
 **/
public class OptionalTest {
    public static void main(String[] args) {
        User user = new User();
        user.setName("zhangsan");
        Optional<User> userOptional = Optional.ofNullable(user);
        String optionMap = userOptional.map((user1) -> user1.getName()).orElse("unknow");
        Optional<String> s = userOptional.map((user1) -> user1.getName());


        System.out.println(optionMap);
    }

    static class User{
        private String name;
        private Integer age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }
    }
}
